<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="scripts/jquery.min.js"></script>

    <script>
        function check(frm) {
            console.log("frm")
            console.log(typeof frm)
            //所有的标签（html、xml）在js世界都是一个个对象
            var fpemail = frm.acname.value;
      
            if (fpemail == "") {
                alert("邮箱不能为空")
                return false;
            }
            return true;
        }
    </script>
</head>
<!--<body style="background-image: url('sourse/log.jpg');background-size: 100%">-->
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <h3 id="ts" style="color:red"></h3>
            <form role="form" action="javascript:void(0)"    style="position: absolute;left: 40%;top: 40%;">
                <div class="form-group"style="margin-top: 30px;">
                    <label for="email">邮&nbsp;&nbsp;&nbsp;箱</label>
                    <input style="height: 25px;margin-left:10px;padding-left: 10px;" type="text" class="form-control"
                           id="email" name="email"
                           placeholder="请输入邮箱"/>

                </div>
                <div class="form-group" style="margin-top: 30px;">
                    <label for="password">密&nbsp;&nbsp;&nbsp;码</label>
                    <input style="height: 25px;margin-left:10px;padding-left: 10px;" type="password"
                           class="form-control" id="password" name="password"/>
                </div>
           <label for="option1" style="font-size:12px;cursor: pointer;color:#8080ff;margin-left:-3px;">管理员</label>
                <input type="radio" id="option1" name="options" value="admin" style="margin-left: -4px;cursor: pointer;">
                <label for="option2" style="font-size:12px;margin-left: 0px;cursor: pointer;color:#8080ff;">顾客</label>
                <input type="radio" id="option2" name="options" value="customer" style="margin-left: -4px;cursor: pointer;"><br>
             
                <button type="button" class="btn btn-default"
                        style="width: 90px;height: 25px; margin-top: 30px;margin-left: 90px;" onclick="forgetpwd()">找回密码
                </button>
             
            </form>
        </div>
    </div>
</div>
</body>
</html>

<script>
    var httpreq=null;
    var ts = document.getElementById("ts")

    function getSelectedValue(){ //判断用户选择
        var radios = document.getElementsByName('options');
        console.log(radios)
        for(var i=0;i<radios.length;i++){
            console.log(radios[i].value)
            if (radios[i].checked) { // 判断当前单选按钮是否被选中

                u=radios[i].value
                break
            }
        }
    }
    function forgetpwd() {
        var email = document.getElementById("email").value;
        var password = document.getElementById("password").value;

        getSelectedValue()
        console.log(u)
       
        if(u==undefined) {
            ts.innerHTML="请选择您的身份"
            return
        }
        
        if(email==""&&password=="") {
            ts.innerHTML="用户名或密码不能为空"
            return
        }
        console.log(email)
      

        if(u=='admin'){
            console.log(u)
            $.ajax(
                {
                    url:"admin/forgetpwd",
                    data:{email:email,password:password},
                    success:function(result){
                        //alert(result);
                        if(result.indexOf("FaIl")!=-1){
                            ts.innerHTML="无效的用户和密码"
                        }else{
                            ts.innerHTML="注册成功，稍后带你到登录界面"
                            setTimeout("window.location.href='login.html',100")
                            // alert(httpreq.responseText)
                        }
                    }
                }
            );
        }else if (u=='customer'){
            console.log(u)
            $.ajax(
                {
                    url:"customer/forgetpwd",
                    data:{email:email,password:password},
                    success:function(result){
                        //alert(result);
                        if(result.indexOf("FaIl")!=-1){
                            ts.innerHTML="无效的用户和密码"
                        }else{
                            ts.innerHTML="注册成功，稍后带你到登录界面"
                            setTimeout("window.location.href='login.html',100")
                            // alert(httpreq.responseText)
                        }
                    }
                }
            );

        } else {
            alert("error")
        }

        // httpreq.send()
    }
  </script>